var t = getApp(), e = "packageG/independent_store/index/index";

Component({
    properties: {
        datas: {
            type: null
        },
        isDiy: {
            type: null
        },
        foot_type: {
            type: null
        }
    },
    data: {
        defaultData: {
            group_title: {
                title: "底部导航名称",
                type: "text",
                value: "默认"
            },
            button_item: {
                title: "",
                type: "bottomItem",
                choose: "2",
                menu_button: [ {
                    id: 0,
                    text: "首页",
                    image: "",
                    icon: "icon-fontclass-shouye",
                    isIcon: "1",
                    link: "/packageG/index/index",
                    isMinApp: "1",
                    gh_id: "",
                    minApp_link: "",
                    sub_button: [],
                    isDefault: !0
                }, {
                    id: 1,
                    text: "分类",
                    image: "",
                    icon: "icon-fontclass-fenlei",
                    isIcon: "1",
                    link: "/packageG/pages/category_v2/category_v2",
                    isMinApp: "1",
                    gh_id: "",
                    minApp_link: "",
                    sub_button: [],
                    isDefault: !0
                }, {
                    id: 2,
                    text: "推广",
                    image: "",
                    icon: "icon-fontclass-tuiguang1",
                    isIcon: "1",
                    link: "/packageG/pages/member/extension/extension",
                    isMinApp: "1",
                    gh_id: "",
                    minApp_link: "",
                    sub_button: [],
                    isDefault: !0
                }, {
                    id: 3,
                    text: "购物车",
                    image: "",
                    icon: "icon-fontclass-gouwuche1",
                    isIcon: "1",
                    link: "/packageG/pages/buy/cart_v2/cart_v2",
                    isMinApp: "1",
                    gh_id: "",
                    minApp_link: "",
                    sub_button: [],
                    isDefault: !0
                }, {
                    id: 4,
                    text: "会员",
                    image: "",
                    icon: "icon-fontclass-huiyuanzhongxin",
                    isIcon: "1",
                    link: "/packageG/member_v2/member_v2",
                    isMinApp: "1",
                    gh_id: "",
                    minApp_link: "",
                    sub_button: [],
                    isDefault: !0
                } ],
                value: {}
            },
            tab_style: {
                title: "",
                type: "tab",
                value: {
                    text_set: {
                        text_show: !0,
                        text_color: "#333333",
                        text_choose_color: "#ff4949"
                    },
                    icon_set: {
                        icon_show: !0,
                        icon_position: "top",
                        icon_color: "#333333",
                        icon_choose_color: "#ff4949"
                    },
                    border_set: {
                        border_show: !1,
                        border_color: "#e7e7eb",
                        border_choose_color: "#29ba9c"
                    },
                    bg_set: {
                        bg_color: "#ffffff",
                        bg_choose_color: "#ffffff"
                    },
                    children_set: {
                        children_color: "#333333",
                        children_choose_color: "#29ba9c",
                        children_bg_color: "#ffffff"
                    }
                }
            }
        },
        storeData: {
            group_title: {
                title: "底部导航名称",
                type: "text",
                value: "默认"
            },
            button_item: {
                title: "",
                type: "bottomItem",
                choose: "2",
                menu_button: [ {
                    id: 0,
                    text: "首页",
                    image: "",
                    icon: "icon-ht_basis_shops",
                    isIcon: "1",
                    link: "/packageG/independent_store/index/index",
                    isMinApp: "1",
                    gh_id: "",
                    minApp_link: "",
                    sub_button: [],
                    isDefault: !0
                }, {
                    id: 1,
                    text: "商品",
                    size: "23",
                    image: "",
                    icon: "icon-ht_basis_goodgroup",
                    isIcon: "1",
                    link: "/packageC/o2o/o2oStore/o2oStore",
                    isMinApp: "1",
                    gh_id: "",
                    minApp_link: "",
                    sub_button: [],
                    isDefault: !0
                }, {
                    id: 2,
                    text: "买单",
                    size: "26",
                    image: "",
                    icon: "icon-shouyintai",
                    isIcon: "1",
                    link: "/packageC/cashier/cashier_pay/cashier_pay",
                    isMinApp: "1",
                    gh_id: "",
                    minApp_link: "",
                    sub_button: [],
                    isDefault: !0
                }, {
                    id: 3,
                    text: "会员",
                    image: "",
                    icon: "icon-fontclass-huiyuanzhongxin",
                    isIcon: "1",
                    link: "/packageG/member_v2/member_v2",
                    isMinApp: "1",
                    gh_id: "",
                    minApp_link: "",
                    sub_button: [],
                    isDefault: !0
                } ],
                value: {}
            },
            tab_style: {
                title: "",
                type: "tab",
                value: {
                    text_set: {
                        text_show: !0,
                        text_color: "#333333",
                        text_choose_color: "#ff4949"
                    },
                    icon_set: {
                        icon_show: !0,
                        icon_position: "top",
                        icon_color: "#333333",
                        icon_choose_color: "#ff4949"
                    },
                    border_set: {
                        border_show: !1,
                        border_color: "#e7e7eb",
                        border_choose_color: "#29ba9c"
                    },
                    bg_set: {
                        bg_color: "#ffffff",
                        bg_choose_color: "#ffffff"
                    },
                    children_set: {
                        children_color: "#333333",
                        children_choose_color: "#29ba9c",
                        children_bg_color: "#ffffff"
                    }
                }
            }
        },
        iPnoneBottomBol: !1,
        emptyImage: "",
        menu_button: [],
        tab_style: {},
        seletedId: "",
        selectedMenuIndex: "",
        selectedSubMenuIndex: "",
        clientWidth: "375",
        routeData: "",
        temp: {},
        routeDataShow: !0,
        default_Id: "",
        cartNum: 0
    },
    lifetimes: {
        attached: function() {
            this.getiPnoneBottom();
            try {
                var e = wx.getStorageSync("yz_basic_info");
                this.setData({
                    basic_info: e.plugin_setting.instation_message,
                    cartNum: t.globalData.cart_num || e.globalParameter.cart_num || 0
                });
            } catch (t) {}
            t.watchGlobalData("cart_num", this.watchCartNum.bind(this));
        },
        moved: function() {},
        detached: function() {}
    },
    attached: function() {},
    ready: function() {
        this.setData({
            clientWidth: wx.getSystemInfoSync().windowWidth
        });
        var a = wx.getStorageSync("default_Id");
        a && this.setData({
            default_Id: a
        });
        var o = getCurrentPages(), n = o[o.length - 1], i = n.__route__;
        this.setData({
            routeData: n.route,
            selectedMenuIndex: ""
        });
        var s = this;
        if (this.data.isDiy && this.data.datas) {
            if (1 == t.globalData.store_alone_temp || i == e) {
                if (s.setData({
                    tab_style: s.data.storeData.tab_style.value
                }), this.getStoreMenu(), s.data.menu_button) for (var u = s.data.menu_button, d = 0; d < u.length; d++) {
                    if (u[d].link.indexOf(s.data.routeData) >= 0 && u[d].sub_button.length <= 0) {
                        s.setData({
                            routeDataShow: !0,
                            selectedMenuIndex: d
                        });
                        break;
                    }
                }
                return;
            }
            if (-1 == this.data.foot_type) this.setData({
                routeDataShow: !1
            }); else if (this.data.foot_type && 1 != this.data.foot_type) {
                if (2 == this.data.foot_type) {
                    if (!this.data.datas.group_title) return void this.setData({
                        routeDataShow: !1
                    });
                    if (this.setData({
                        menu_button: this.data.datas.button_item.menu_button,
                        tab_style: this.data.datas.tab_style.value
                    }), this.data.datas.button_item && this.data.datas.button_item.menu_button) {
                        for (var r = this.data.datas.button_item.menu_button, l = 0; l < r.length; l++) {
                            var c = r[l].link;
                            if (c.indexOf(s.data.routeData) >= 0 && r[l].sub_button.length <= 0) {
                                if ("packageG/newDiy/newDiy" != s.data.routeData) {
                                    s.setData({
                                        selectedMenuIndex: l
                                    });
                                    break;
                                }
                                if (n.options && c.indexOf(Number(n.options.page_id)) >= 0) {
                                    s.setData({
                                        selectedMenuIndex: l
                                    });
                                    break;
                                }
                            }
                        }
                        for (var _ = 0; _ < r.length; _++) for (var f = 0; f < r[_].sub_button.length; f++) {
                            if (r[_].sub_button[f].link.indexOf(s.data.routeData) >= 0) {
                                s.setData({
                                    selectedSubMenuIndex: _,
                                    seletedId: r[_].sub_button[f].id
                                });
                                break;
                            }
                        }
                    }
                }
            } else if (this.data.datas.group_title ? this.setData({
                menu_button: this.data.datas.button_item.menu_button,
                tab_style: this.data.datas.tab_style.value
            }) : this.setData({
                menu_button: this.data.defaultData.button_item.menu_button,
                tab_style: this.data.defaultData.tab_style.value
            }), this.data.menu_button) {
                for (var b = this.data.menu_button, g = 0; g < b.length; g++) {
                    var h = b[g].link;
                    if (h.indexOf(s.data.routeData) >= 0 && b[g].sub_button.length <= 0) {
                        if ("packageG/newDiy/newDiy" != s.data.routeData) {
                            s.setData({
                                selectedMenuIndex: g
                            });
                            break;
                        }
                        if (n.options && h.indexOf(Number(n.options.page_id)) >= 0) {
                            s.setData({
                                selectedMenuIndex: g
                            });
                            break;
                        }
                    }
                }
                for (var p = 0; p < b.length; p++) for (var m = 0; m < b[p].sub_button.length; m++) {
                    if (b[p].sub_button[m].link.indexOf(s.data.routeData) >= 0) {
                        s.setData({
                            selectedSubMenuIndex: p
                        }), s.data.default_Id ? s.setData({
                            seletedId: s.data.default_Id
                        }) : s.setData({
                            seletedId: b[p].sub_button[m].id
                        });
                        break;
                    }
                }
            }
        } else if (1 == t.globalData.store_alone_temp || i == e) {
            if (console.log(wx.getStorageSync("storeMenu"), "storeMenu"), s.setData({
                tab_style: s.data.storeData.tab_style.value
            }), this.getStoreMenu(), s.data.menu_button) for (var D = s.data.menu_button, x = 0; x < D.length; x++) {
                if (D[x].link.indexOf(s.data.routeData) >= 0 && D[x].sub_button.length <= 0) {
                    s.setData({
                        routeDataShow: !0,
                        selectedMenuIndex: x
                    });
                    break;
                }
            }
        } else wx.getStorage({
            key: "yz_basic_info",
            success: function(t) {
                if (t.data) {
                    if (s.setData({
                        temp: t.data.home
                    }), (s.data.routeData.indexOf("o2oHome") >= 0 || s.data.routeData.indexOf("VideoList") >= 0 || s.data.routeData.indexOf("easyRefuel") >= 0 || s.data.routeData.indexOf("VideoDetail") >= 0 || s.data.routeData.indexOf("groupCode") >= 0 || s.data.routeData.indexOf("questionnaireIndex") >= 0 || s.data.routeData.indexOf("groupCodeRanking") >= 0 || s.data.routeData.indexOf("groupCodeShow") >= 0 || s.data.routeData.indexOf("groupCodeRecord") >= 0 || s.data.routeData.indexOf("groupCodeData") >= 0) && s.setData({
                        routeDataShow: !0
                    }), s.data.iPnoneBottomBol ? s.triggerEvent("showcarrfoot_ipx", !0) : s.triggerEvent("showcarrfoot", !0), 
                    s.data.temp.item.menus && s.data.temp.item.menus.page_info) {
                        var e = JSON.parse(s.data.temp.item.menus.page_info);
                        s.setData({
                            menu_button: e.button_item.menu_button,
                            tab_style: e.tab_style.value
                        });
                    } else s.setData({
                        menu_button: s.data.defaultData.button_item.menu_button,
                        tab_style: s.data.defaultData.tab_style.value
                    });
                    if (s.data.menu_button) {
                        for (var a = s.data.menu_button, o = 0; o < a.length; o++) {
                            var i = a[o].link;
                            if (i.indexOf(s.data.routeData) >= 0 && a[o].sub_button.length <= 0) {
                                if ("packageG/newDiy/newDiy" != s.data.routeData) {
                                    s.setData({
                                        routeDataShow: !0,
                                        selectedMenuIndex: o
                                    });
                                    break;
                                }
                                if (n.options && i.indexOf(Number(n.options.page_id)) >= 0) {
                                    s.setData({
                                        routeDataShow: !0,
                                        selectedMenuIndex: o
                                    });
                                    break;
                                }
                            }
                        }
                        for (var u = 0; u < a.length; u++) for (var d = 0; d < a[u].sub_button.length; d++) {
                            if (a[u].sub_button[d].link.indexOf(s.data.routeData) >= 0) {
                                s.setData({
                                    routeDataShow: !0,
                                    selectedSubMenuIndex: u,
                                    seletedId: a[u].sub_button[d].id
                                });
                                break;
                            }
                        }
                    }
                }
            },
            fail: function() {
                s.getTemp();
            }
        });
    },
    pageLifetimes: {
        show: function() {},
        hide: function() {},
        resize: function() {}
    },
    methods: {
        getStoreMenu: function() {
            var e = this, a = t.getNetAddresss("plugin.store-alone-temp.frontend.home.get-set-nav-data");
            t._getNetWork({
                showToastIn: !1,
                url: a,
                success: function(t) {
                    var a = t.data;
                    1 == a.result && (console.log(a.data), wx.setStorageSync("storeMenu", a.data), e.setData({
                        menu_button: a.data
                    }));
                },
                fail: function(t) {}
            });
        },
        getTemp: function() {
            var e = this, a = t.getNetAddresss("home-page.wxapp");
            t._getNetWork({
                showToastIn: !1,
                url: a,
                success: function(t) {
                    var a = t.data;
                    if (1 == a.result) {
                        if (e.setData({
                            temp: a.data
                        }), (e.data.routeData.indexOf("o2oHome") >= 0 || e.data.routeData.indexOf("VideoList") >= 0 || e.data.routeData.indexOf("easyRefuel") >= 0 || e.data.routeData.indexOf("VideoDetail") >= 0 || e.data.routeData.indexOf("groupCode") >= 0 || e.data.routeData.indexOf("questionnaireIndex") >= 0 || e.data.routeData.indexOf("groupCodeRanking") >= 0 || e.data.routeData.indexOf("groupCodeShow") >= 0 || e.data.routeData.indexOf("groupCodeRecord") >= 0 || e.data.routeData.indexOf("groupCodeData") >= 0) && e.setData({
                            routeDataShow: !0
                        }), e.data.iPnoneBottomBol ? e.triggerEvent("showcarrfoot_ipx", !0) : e.triggerEvent("showcarrfoot", !0), 
                        e.data.temp.item.foot && e.data.temp.item.foot.page_info) {
                            var o = JSON.parse(e.data.temp.item.foot.page_info);
                            e.setData({
                                menu_button: o.button_item.menu_button,
                                tab_style: o.tab_style.value
                            });
                        } else e.setData({
                            menu_button: e.data.defaultData.button_item.menu_button,
                            tab_style: e.data.defaultData.tab_style.value
                        });
                        if (e.data.menu_button) {
                            for (var n = e.data.menu_button, i = 0; i < n.length; i++) {
                                var s = n[i].link;
                                if (s.indexOf(e.data.routeData) >= 0 && n[i].sub_button.length <= 0) {
                                    if ("packageG/newDiy/newDiy" != e.data.routeData) {
                                        e.setData({
                                            routeDataShow: !0,
                                            selectedMenuIndex: i
                                        });
                                        break;
                                    }
                                    if (currentPage.options && s.indexOf(Number(currentPage.options.page_id)) >= 0) {
                                        e.setData({
                                            routeDataShow: !0,
                                            selectedMenuIndex: i
                                        });
                                        break;
                                    }
                                }
                            }
                            for (var u = 0; u < n.length; u++) for (var d = 0; d < n[u].sub_button.length; d++) {
                                if (n[u].sub_button[d].link.indexOf(e.data.routeData) >= 0) {
                                    e.setData({
                                        routeDataShow: !0,
                                        selectedSubMenuIndex: u,
                                        seletedId: n[u].sub_button[d].id
                                    });
                                    break;
                                }
                            }
                        }
                    }
                },
                fail: function(t) {}
            });
        },
        handle_data: function(t) {
            var e = {};
            return Object.keys(t).map(function(a) {
                e[a] = t[a].value;
            }), e;
        },
        selectedMenu: function(e) {
            var a = e.currentTarget.dataset.item, o = e.currentTarget.dataset.index;
            if (this.data.selectedMenuIndex !== o) {
                if (this.setData({
                    selectedSubMenuIndex: "",
                    selectedMenuIndex: o
                }), 0 == a.sub_button.length) if (2 == a.isMinApp) if (a.gh_id) if (a.minApp_link) try {
                    wx.navigateToMiniProgram({
                        appId: a.gh_id,
                        path: a.minApp_link,
                        extraData: {},
                        envVersion: "release",
                        success: function(t) {},
                        fail: function(t) {
                            wx.showToast({
                                title: "小程序跳转失败",
                                icon: "none",
                                duration: 2e3
                            });
                        }
                    });
                } catch (e) {
                    wx.showToast({
                        title: "小程序跳转失败",
                        icon: "none",
                        duration: 2e3
                    });
                } else wx.showToast({
                    title: "请设置跳转小程序后的跳转链接",
                    icon: "none",
                    duration: 2e3
                }); else wx.showToast({
                    title: "请设置小程序所需跳转appId",
                    icon: "none",
                    duration: 2e3
                }); else {
                    if (a.link === this.data.routeData) return;
                    var n = a.link;
                    if (1 == t.globalData.store_alone_temp && (n += "?store_id=".concat(t.globalData.STORE_ID)), 
                    n) try {
                        1 != t.globalData.store_alone_temp || 1 != a.id && 2 != a.id ? wx.redirectTo({
                            url: n,
                            fail: function() {
                                t.tips("链接设置错误:" + n);
                            }
                        }) : wx.navigateTo({
                            url: n
                        });
                    } catch (e) {
                        t.tips("链接设置错误:" + n);
                    } else t.tips("请设置跳转链接");
                }
            } else this.setData({
                selectedSubMenuIndex: "",
                selectedMenuIndex: ""
            });
        },
        selectedSubMenu: function(e) {
            var a = e.currentTarget.dataset.index, o = e.currentTarget.dataset.item;
            if (2 == o.isMinApp) if (o.gh_id) if (o.minApp_link) try {
                wx.navigateToMiniProgram({
                    appId: o.gh_id,
                    path: o.minApp_link,
                    extraData: {},
                    envVersion: "release",
                    success: function(t) {},
                    fail: function(t) {
                        wx.showToast({
                            title: "小程序跳转失败",
                            icon: "none",
                            duration: 2e3
                        });
                    }
                });
            } catch (e) {
                wx.showToast({
                    title: "小程序跳转失败",
                    icon: "none",
                    duration: 2e3
                });
            } else wx.showToast({
                title: "请设置跳转小程序后的跳转链接",
                icon: "none",
                duration: 2e3
            }); else wx.showToast({
                title: "请设置小程序所需跳转appId",
                icon: "none",
                duration: 2e3
            }); else {
                if (o.link === this.data.routeData) return;
                var n = o.link;
                this.setData({
                    selectedSubMenuIndex: a
                });
                var i = this.data.menu_button[this.data.selectedMenuIndex].sub_button[this.data.selectedSubMenuIndex];
                if (this.setData({
                    seletedId: i.id,
                    default_Id: i.id
                }), wx.setStorageSync("default_Id", this.data.default_Id), n) try {
                    wx.redirectTo({
                        url: n,
                        fail: function() {
                            t.tips("链接设置错误:" + n);
                        }
                    });
                } catch (e) {
                    wx.showToast({
                        title: "链接设置错误:" + n,
                        icon: "none",
                        duration: 2e3
                    });
                } else wx.showToast({
                    title: "请设置跳转链接",
                    icon: "none",
                    duration: 2e3
                });
            }
        },
        getiPnoneBottom: function() {
            try {
                wx.getStorageSync("iPhoneBottom") && this.setData({
                    iPnoneBottomBol: !0
                });
            } catch (t) {}
        },
        goindex: function() {
            wx.redirectTo({
                url: "/packageG/index/index"
            });
        },
        gocategory: function() {
            wx.redirectTo({
                url: "/packageG/pages/category_v2/category_v2"
            });
        },
        goextension: function() {
            wx.redirectTo({
                url: "/packageG/pages/member/extension/extension"
            });
        },
        gocart: function() {
            wx.redirectTo({
                url: "/packageG/pages/buy/cart_v2/cart_v2"
            });
        },
        gomember: function() {
            wx.redirectTo({
                url: "/packageG/member_v2/member_v2"
            });
        },
        watchCartNum: function(t) {
            this.setData({
                cartNum: t
            });
        }
    }
});